/*
 * test_console.cpp
 *
 *  Created on: Nov 12, 2013
 *      Author: killerg
 */


#include "share/console2.h"

#include <unistd.h>


bool running = true;
std::string handle_shut(Arg &arg_, void* gm_) {
    running = false;
    return "success";
}

std::string handle_stat(Arg &arg_, void* gm_) {
    return "success";
}

console_t2 con;
#define CONLOG(mask, fmt, arg...) con.log(mask, #mask ": " fmt "\r\n", ##arg)

bool test_console() {
    if (!con.init_log("test")) {
        return false;
    }
    if (!con.init_net()) {
        UTIL_LOG(E, "console init net err");
        return false;
    }


    con.reg("shut", "", handle_shut);
    con.reg("stat", "", handle_stat);

    CONLOG(I, "hello init ok");

    if (!con.start_accept("0.0.0.0", 9877)) {
        CONLOG(E, "con::start_accept error");
        return false;
    }


    for (int i=0; running; ++i) {
        CONLOG(I, "%s", fmt_cstr("%d\n", i));
//        con.update();
        sleep(1);
    }

//    con.destroy();

    return true;
}
